package com.test4;

import com.test3.Executor;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;

public class CompLog {

    static ThreadPoolExecutor executor = Executor.get();


    public static void main(String[] args) {
        //executor.setThreadFactory(new handle());
        System.err.println(new CompLog().a());
    }

    public Integer a (){

        executor.execute(()->{

            try {
                Thread.sleep(1000);
                throw new RuntimeException("-1");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        CompletableFuture fu = new CompletableFuture();


//        CompletableFuture.runAsync(() -> {
//            // 异步操作
//            int a = 1/0;
//            throw new RuntimeException("123456");
//        },executor);

        return 1;
    }

    static class handle implements ThreadFactory{

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setUncaughtExceptionHandler((t, ex) -> {
                ex.printStackTrace();
                System.err.println("线程池中发生未捕获的异常：" + ex.getMessage());
                //System.out.println("线程池中发生未捕获的异常：" + ex.getMessage(), ex);
            });
            return thread;
        }
    }



}
